import * as path from 'node:path';
import { TornaDocDetail } from '../types/type';
import { getApiFileName } from './getApiFileName';

export type GetOutputFilePathOptions = {

  /**
   * 输出的目录路径
   * @date 1/24/2024 - 6:23:03 PM
   *
   * @type {string}
   */
  outputDirPath: string,

  /**
   * 接口详情
   * @date 1/24/2024 - 6:23:25 PM
   *
   * @type {TornaDocDetail}
   */
  detail: TornaDocDetail,

  /**
   * 输出文件的后缀名
   */
  extension: 'dart' | 'ts'
};



/**
 * 获取接口文件的最终输出路径
 * @date 1/24/2024 - 6:22:26 PM
 *
 * @export
 * @async
 * @param {GetOutputFilePathOptions} opts 参数
 * @returns {Promise<string>} 接口文件的路径
 */
export async function getOutputFilePath(opts: GetOutputFilePathOptions): Promise<string> {
  const { detail, outputDirPath, extension } = opts;
  const { id, name } = detail;
  const fileName = getApiFileName(detail);
  if (!fileName) { throw new Error(`url got empty, id: ${id}, name: ${name}`); }
  return path.join(outputDirPath, fileName + '.' + extension);
}
